package tech.aistar.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.aistar.mapper.ProductMapper;
import tech.aistar.model.pojo.Product;
import tech.aistar.model.vo.ProductQueryVo;
import tech.aistar.service.IProductService;

import java.util.List;

@Service
public class ProductServiceImpl implements IProductService {

    @Autowired
    IProductService iProductService;

    @Autowired
    ProductMapper productMapper;

    @Override
    public PageInfo<Product> findAll(Integer pageNow,Integer pageSize) {

        PageHelper.startPage(pageNow,pageSize);
        List<Product> productList = productMapper.findAll();
        PageInfo<Product> pageInfo = new PageInfo<>(productList);

        return pageInfo;

    }

    @Override
    public PageInfo<Product> findAll(ProductQueryVo vo, Integer pageNow, Integer pageSize) {

        PageHelper.startPage(pageNow,pageSize);
        List<Product> productList = productMapper.findByConditional(vo);
        PageInfo<Product> pageInfo = new PageInfo<>(productList);
        return pageInfo;
    }

    @Override
    public Product getById(Integer id) {

        Product product = productMapper.getById(id);

        return product;
    }
}
